//
//  HomeGoodsDetailHeaderModel.m
//  FD
//
//  Created by Yasin on 2018/10/20.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "HomeGoodsDetailHeaderModel.h"

@implementation HomeGoodsDetailHeaderModel

- (NSString *)thumbnail {
    return [NSString stringWithFormat:@"%@%@",kPicDomain,_thumbnail];
}

+ (NSDictionary *)mj_replacedKeyFromPropertyName {
    return @{@"goodsId":@"id"};
}

- (NSString *)description {
    NSArray *ptys = [HomeGoodsDetailHeaderModel rb_objPropeties];
    
    NSString *des = [[self dictionaryWithValuesForKeys:ptys] description];
    return des;
}


#pragma mark - 2019-1-17计算默认选中的价格
- (NSNumber *)defaultSelectPrice {

    if (!self.ingredientClassifyList) {
        return @(0); //空数组
    }
    
    //2019-1-17 只取 currentPrice
    CGFloat defaultSelectPrice = 0.0; //默认选中价格
    
    NSArray *classifyListArr = self.ingredientClassifyList;
    for (NSDictionary *firstLevelDic in classifyListArr) {
        NSNumber *only = firstLevelDic[@"only"]; //是否是单选
        if ([only isEqualToNumber:@(1)]) { //单选
            NSNumber *defaultSelect = firstLevelDic[@"defaultSelect"];
            NSArray *ingredientList = firstLevelDic[@"ingredientList"];
            
            for (NSDictionary *secondLevelDic in ingredientList) {
                NSNumber *ingreDientId = secondLevelDic[@"id"];
                if ([defaultSelect isEqualToNumber:ingreDientId]) {
                    //取 currentPrice
                    NSNumber *currentPrice = secondLevelDic[@"currentPrice"];
                    
                    defaultSelectPrice += [currentPrice floatValue];
                }
            }
        }
    }
    
    FDLog(@"默认选中的价格是:%f",defaultSelectPrice);
    return @(defaultSelectPrice); //默认选中的价格是
}
@end
